package com.hongye.furniture.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hongye.common.log.annotation.Log;
import com.hongye.common.log.enums.BusinessType;
import com.hongye.common.security.annotation.RequiresPermissions;
import com.hongye.furniture.domain.HyFurniture;
import com.hongye.furniture.service.IHyFurnitureService;
import com.hongye.common.core.web.controller.BaseController;
import com.hongye.common.core.web.domain.AjaxResult;
import com.hongye.common.core.utils.poi.ExcelUtil;
import com.hongye.common.core.web.page.TableDataInfo;

/**
 * 家具列表Controller
 * 
 * @author 白杨
 * @date 2025-02-14
 */
@RestController
@RequestMapping("/furniture")
public class HyFurnitureController extends BaseController
{
    @Autowired
    private IHyFurnitureService hyFurnitureService;


    /**
     * 根据区县id获取该区下所有家具
     */

    @GetMapping("/findFurnitureByRegionId/{categoryId}")
    public List<HyFurniture> findFurnitureByRegionId(@RequestParam Long categoryId)
    {
        return hyFurnitureService.findFurnitureByRegionId(categoryId);
    }


    /**
     * 查询家具列表列表
     */

    @GetMapping("/list")
    public TableDataInfo list(HyFurniture hyFurniture)
    {
        startPage();
        List<HyFurniture> list = hyFurnitureService.selectHyFurnitureList(hyFurniture);
        return getDataTable(list);
    }

    /**
     * 导出家具列表列表
     */

    @Log(title = "家具列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HyFurniture hyFurniture)
    {
        List<HyFurniture> list = hyFurnitureService.selectHyFurnitureList(hyFurniture);
        ExcelUtil<HyFurniture> util = new ExcelUtil<HyFurniture>(HyFurniture.class);
        util.exportExcel(response, list, "家具列表数据");
    }

    /**
     * 获取家具列表详细信息
     */

    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(hyFurnitureService.selectHyFurnitureById(id));
    }

    /**
     * 新增家具列表
     */

    @Log(title = "家具列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HyFurniture hyFurniture)
    {
        return toAjax(hyFurnitureService.insertHyFurniture(hyFurniture));
    }

    /**
     * 修改家具列表
     */

    @Log(title = "家具列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HyFurniture hyFurniture)
    {
        return toAjax(hyFurnitureService.updateHyFurniture(hyFurniture));
    }

    /**
     * 删除家具列表
     */

    @Log(title = "家具列表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(hyFurnitureService.deleteHyFurnitureByIds(ids));
    }
}
